import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/Home.vue'),
    redirect: '/hotel-search'
  },
  {
    path: '/hotel-search',
    name: 'HotelSearch',
    component: () => import('../views/HotelSearch.vue'),
    meta: { keepAlive: true }
  },
  // 这些路由将被当作弹窗处理，不会实际导航
  {
    path: '/hotel-detail/:hotelId',
    name: 'HotelDetail',
    component: () => import('../views/HotelSearch.vue'),
    props: true,
    meta: { isDialog: true, dialogType: 'hotel-detail' }
  },
  {
    path: '/room-products/:hotelId',
    name: 'RoomProducts',
    component: () => import('../views/HotelSearch.vue'),
    props: true,
    meta: { isDialog: true, dialogType: 'room-products' }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  }
})

export default router